<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

<!-- BEGIN: load jquery -->
<script language="javascript" type="text/javascript"
	src="<?php echo base_url()?>js/jqplot/jquery.js">
</script>
<!-- END: load jquery -->

<style type="text/css">
div.field {
	background-color: #C4E1FF;
	font-size: 13pt;
}

div.name {
	font-size: 16pt;
}

label {
	font-size: 16pt;
}

button {
	margin-left: 10px;
	margin-right: 10px;
}

td {
	width: 300px;
}

td.health_data {
	background-color: #C4E1FF;
}
</style>
</head>
<body>

<script language="javascript" type="text/javascript">
$(
		function()
		{
			$(".expand_btn").attr("tag", "false");
			
			$(".expand_btn").click(
					function()
					{
						tag = $(this).attr("tag");
						target = $(this).attr("datablock");

						if(tag == "false")
						{
							$(this).attr("tag", "true");
							$("#"+target).css("display", "block");
						}else
						{
							$(this).attr("tag", "false");
							$("#"+target).css("display", "none");
						}
					}
					);
		}
);
</script>

	<?php
	if(!isset($friend_health_update) && !isset($friend_symptom_update))
	{
		echo "您的朋友近期没有更新！";
		exit();
	}
	
	$friend_update_uni = array();
	foreach($friend_health_update as $friend_uid=>$update_info)
	{
		if(!array_key_exists($friend_uid, $friend_update_uni))
			$friend_update_uni[$friend_uid] = array();
		$update_uni = &$friend_update_uni[$friend_uid];
		for ($i = 0; $i < count($update_info); $i++)
		{
			$elem = $update_info[$i];
			$field = $elem["field"];
			if(!valid_field($field))
				continue;

			$name = translate_field($field);
			$date = $elem["date"];
			$desc = $elem["value"];
			
			$info = array("name"=>$name, "date"=>$date, "desc"=>$desc);
			$update_uni[] = $info;
		}
	}
	
	foreach($friend_symptom_update as $friend_uid=>$update_info)
	{
		if(!array_key_exists($friend_uid, $friend_update_uni))
			$friend_update_uni[$friend_uid] = array();
		$update_uni = &$friend_update_uni[$friend_uid];
		
		for ($i = 0; $i < count($update_info); $i++)
		{
			$elem = $update_info[$i];
			$name = "症状";
			$date = $elem["date"];
			$desc = get_symptom_name_by($elem["symptomType"]);
			
			$info = array("name"=>$name, "date"=>$date, "desc"=>$desc);
			$update_uni[] = $info;
		}
	}
	
	function my_sort($info_a, $info_b)
	{
		$date_str_a = $info_a["date"];
		$date_str_b = $info_b["date"];
		
		date_default_timezone_set("PRC");
		
		$time_a = strtotime($date_str_a);
		$time_b = strtotime($date_str_b);
		
		return $time_a < $time_b;
	}

		


	$is_update = false;
	foreach($friend_update_uni as $friend_uid=>$update_info)
	{
		if(count($update_info) == 0)
		{
			continue;
		}

		if(!$is_update)
		{
			echo "<center>";
			echo "<label>您的朋友近期更新了如下数据:</label>";
			echo "</center>";
			echo "<hr>";
			echo "<br>";
			$is_update = true;
		}

		usort($update_info, "my_sort");
		
		$data_block_id = "health_data_block_".$friend_uid;
		echo "<table>";
		echo "<tr>";
		echo "<td><label>".get_name_by_uid($friend_uid)."(".get_nickname_by_uid($friend_uid).")"."</label></td>";
		echo "<td><button class=\"expand_btn\" datablock=\"$data_block_id\">"."展开/收起"."</button></td>";
		echo "</tr>";
		echo "<tr>";
		$info = $update_info[0];
		echo "<td class=\"health_data\"><label>".$info["name"]."</label></td>";
		echo "<td class=\"health_data\"><label>".$info["desc"]."</label></td>";
		echo "<td class=\"health_data\"><label>".$info["date"]."</label></td>";
		echo "</tr>";
		echo "</table>";
		echo "<table id=\"$data_block_id\" style=\"display:none\">";
		if(count($update_info) >= 1){
			for ($i = 1; $i < count($update_info); $i++)
			{
				$info = $update_info[$i];
				echo "<tr>";
				echo "<td class=\"health_data\"><label>".$info["name"]."</label></td>";
				echo "<td class=\"health_data\"><label>".$info["desc"]."</label></td>";
				echo "<td class=\"health_data\"><label>".$info["date"]."</label></td>";
				echo "</tr>";
			}
		}
		echo "</table>";
		
		echo "<br/>";
	}

	if(!$is_update)
	{
		echo "您的朋友近期没有更新！";
	}
?>
</body>
</html>
